﻿<!--_meta 作为公共模版分离出去-->
<!DOCTYPE HTML>
<html>
<head>
<!--#header start-->
{include file="public/_meta" /}
<!--#header end-->

<title>新建用户组</title>
<meta name="keywords" content="">
<meta name="description" content="">
</head>
<body>
<article class="page-container">
	<form action="" method="post" class="form form-horizontal" id="form-admin-role-add">
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>角色名称：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<input type="text" class="input-text" value="" placeholder="" id="roleName" name="title">
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-3">是否启用：</label>
			<div class="formControls col-xs-8 col-sm-9 skin-minimal">
				<div class="radio-box">
				 <input type="radio" id="radio-1" name="status" checked value="1">
				 <label for="radio-1">&nbsp;启用</label>
			 </div>
			 <div class="radio-box">
				 <input type="radio" id="radio-2" name="status" value="0">
				 <label for="radio-2">&nbsp;禁用</label>
			 </div>
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-3">备注：</label>
			<div class="formControls col-xs-8 col-sm-9">
				<textarea name="remark" class="textarea"  placeholder="说点什么...最少输入5个字符" datatype="*5-50" dragonfly="true" nullmsg="备注不能为空！" onKeyUp="$.Huitextarealength(this,50)"></textarea>
				<p class="textarea-numberbar"><em class="textarea-length">0</em>/50</p>
			</div>
		</div>
		<div class="row cl">
			<label class="form-label col-xs-4 col-sm-3">网站角色：</label>
			<div class="formControls col-xs-8 col-sm-9">

				{volist name="ruleList" id="list"}
			   <!-- 一级节点 -->
			  	{if condition="array_key_exists('child',$list)"}
						<dl class="permission-list">
							<dt>
								<label>
									<input type="checkbox" value="" name="user-Character-0" id="user-Character-0">
									{$list.menu_name}({$list.name})</label>
							</dt>
							<dd>
								<dl class="cl permission-list2">
									<dt>
										<label class="">
											<input type="checkbox" value="{$list.id}" name="rules[]" id="user-Character-0-0">
											{$list.name}</label>
									</dt>
									<dd>
										{volist name="list.child" id="sonList"}
											 <!-- 二级节点 -->
												 <label class="">
													 <input type="checkbox" value="{$sonList.id}" name="rules[]" id="user-Character-0-0-{$sonList.id}">
													 {$sonList.menu_name}
												</label>
											 <!-- 二级节点 end-->
										{/volist}
		              </dd>
								</dl>
							</dd>
						</dl>
			  	<!-- 一级节点 end-->
				 	{/if}
				{/volist}
			</div>
		</div>
		<div class="row cl">
			<div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
				<button type="submit" class="btn btn-success radius" id="admin-role-save" name="admin-role-save"><i class="icon-ok"></i> 确定</button>
			</div>
		</div>
	</form>
</article>

<!--#header start-->
{include file="public/_footer" /}
<!--#header end-->

<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript" src="__ADMIN__/lib/jquery.validation/1.14.0/jquery.validate.js"></script>
<script type="text/javascript" src="__ADMIN__/lib/jquery.validation/1.14.0/validate-methods.js"></script>
<script type="text/javascript" src="__ADMIN__/lib/jquery.validation/1.14.0/messages_zh.js"></script>
<script type="text/javascript">
$(function(){

	//全选&反选
	$(".permission-list dt input:checkbox").click(function(){
		$(this).closest("dl").find("dd input:checkbox").prop("checked",$(this).prop("checked"));
	});
	$(".permission-list2 dd input:checkbox").click(function(){
		var l =$(this).parent().parent().find("input:checked").length;
		var l2=$(this).parents(".permission-list").find(".permission-list2 dd").find("input:checked").length;
		if($(this).prop("checked")){
			$(this).closest("dl").find("dt input:checkbox").prop("checked",true);
			$(this).parents(".permission-list").find("dt").first().find("input:checkbox").prop("checked",true);
		}
		else{
			if(l==0){
				$(this).closest("dl").find("dt input:checkbox").prop("checked",false);
			}
			if(l2==0){
				$(this).parents(".permission-list").find("dt").first().find("input:checkbox").prop("checked",false);
			}
		}
	});

	$("#form-admin-role-add").validate({
		rules:{
			roleName:{
				required:true,
			},
		},
		onkeyup:false,
		focusCleanup:true,
		success:"valid",
		submitHandler:function(form){

			layer.load(0, {
				shade: [0.1,'#fff'] //0.1透明度的白色背景
			});
			$(form).ajaxSubmit({
				type: 'post',
				url: "{:url('Auth/createGroup')}" ,
				success: function(result){
				  if (result.state) {
					  	// 关闭ifram
						setTimeout(function(){
							layer.msg(result.msg,{icon:1,time:1000});
							var index = parent.layer.getFrameIndex(window.name);
							parent.layer.close(index);
						}, 2000);
						 layer.msg(result.msg,{icon:1,time:1000});
				  }else {
						 layer.msg(result.msg,{icon:5,time:1000});
				  }
				},
					error: function(XmlHttpRequest, textStatus, errorThrown){
					layer.msg('网络连接失败!',{icon:5,time:1000});
				}
			});

		 setTimeout(function(){
			layer.closeAll('loading');
			// var index = parent.layer.getFrameIndex(window.name);
			// parent.layer.close(index);
		}, 3000);
		}
	});
});
</script>
<!--/请在上方写此页面业务相关的脚本-->
</body>
</html>
